<?php
/**
 * Created by PhpStorm.
 * User: zhanghua
 * Date: 2018/9/21
 * Time: 18:24
 */

namespace app\dlc\service;


use app\common\service\ModelBaseService;
use app\dlc\model\AdminPerm;
use app\dlc\model\AdminRole;
use app\dlc\model\AdminRolePermRelation;
use think\Db;

class AdminPermService extends ModelBaseService
{
    protected $modelName = 'app\\dlc\\model\\AdminPerm';

    /**
     * 根据角色获取菜单
     * @param $roleId
     * @return false|static[]
     */
    protected function getAdminMenuByRole($roleId)
    {
        $roleId = max(0, intval($roleId));
        $result = Db::table('dlc_admin_role_perm_relation')
            ->alias('a')
            ->join('dlc_admin_perm b', 'a.perm_id = b.id')
            ->where('a.role_id', $roleId)
            ->where('b.is_menu', 1)
            ->field('b.*')
            ->select();
        ;
        return $result;
    }

    /**
     * 获取所有一级的菜单
     * @return false|static[]
     */
    protected function getTopMenu()
    {
        return AdminPerm::Where('is_menu', 1)->where('menu_pid', 0)->all();
    }

    /**
     * 获取所有的菜单
     */
    protected function getAllMenu()
    {
        return AdminPerm::Where('is_menu', 1)->all();
    }

    /**
     * @param $menuId
     * @return bool
     */
    protected function adminPermDel($menuId)
    {
        return $result = AdminPerm::destroy($menuId);
    }


}